package com.ux.util
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	
	
	/**
	 * 
	 * @author winnie
	 * 
	 */	
	public class LoadingUtil extends Loader
	{
		private var req : URLRequest;
		private var loadpath: String;
		
		private var _loadingPercentage : int;
		private var _loadData : DisplayObject;
		
		public function LoadingUtil( path:String )
		{
			super();
			
			this.loadpath = path;
			
			this.req = new URLRequest();
			req.url = loadpath;
			
			this.contentLoaderInfo.addEventListener( Event.INIT, onLoadInit );
			this.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress );
		}
		
		
		private function onLoadProgress( e:ProgressEvent ):void
		{
			this._loadingPercentage = Math.floor( e.bytesLoaded / e.bytesTotal );
			trace( loadpath + "  percent : " + loadingPercentage );
		}
		
		private function onLoadInit( e:Event ):void
		{
			this._loadData = ( e.currentTarget as Loader ).content;
		}
		
		
		
		
		
		
		public function loadStart():void
		{
			this.load( this.req );
		}
		
		
		/**
		 * return load Data
		 */		
		public function get loadData():DisplayObject
		{
			return this.loadData;
		}
		
		/**
		 *  return loading percentage. 
		 */		
		public function get loadingPercentage():int
		{
			return loadingPercentage;
		}
		
		
		
	}
}







